package com.duodao.login.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.duodao.login.mapper.UserDao;
import com.duodao.login.model.User;
import com.duodao.login.service.UserService;


@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public User findByAccountNo(String accountNo) {
		return userDao.loadByAccountNo(accountNo);
	}

	@Override
	public void saveUser(User user) {
		try {
			userDao.addUser(user);
		} catch (Exception e) {
			try {
				throw new Exception(e.getMessage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

	@Override
	public String login(String accountNo) {
		return userDao.login(accountNo);
	}

	@Override
	public List<User> findAll() {
		return userDao.findAll();
	}

	@Override
	public Integer loadUserCount(User user) {
		return userDao.loadUserCount(user);
	}

	@Override
	public void removeUser(Integer userID) {
		try {
			userDao.deleteByUserID(userID);
		} catch (Exception e) {
			try {
				throw new Exception(e.getMessage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

	@Override
	public void modifyUser(User user) {
		try {
			if(user!=null){
				userDao.updateUser(user);
			}
		} catch (Exception e) {
			try {
				throw new Exception(e.getMessage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

	@Override
	public List<User> selectAllUser(Map<String, Object> map) {
		return userDao.selectAllUser(map);
	}


}
